using UnityEngine;
using UnityEngine.UI;
using QFramework;
using QFramework.FlyBird;

namespace QFramework.Example
{
    public class UIGamePanelData : UIPanelData
    {
    }
    public partial class UIGamePanel : UIPanel
    {
        protected override void OnInit(IUIData uiData = null)
        {
            mData = uiData as UIGamePanelData ?? new UIGamePanelData();
            // please add init code here
            FlappyBird.BestScore.RegisterWithInitValue(bestScore =>
            {
                BestScoreText.text = "Best Score:" + bestScore;
            }).UnRegisterWhenGameObjectDestroyed(gameObject);
            FlappyBird.Score.RegisterWithInitValue(score =>
            {
                ScoreText.text = score.ToString();
            }).UnRegisterWhenGameObjectDestroyed(gameObject);

            ScoreText.Hide();
            FlappyBird.GameState.RegisterWithInitValue(gameState =>
            {
                if(gameState==GameStates.NotStart)
                {
                    ScoreText.Hide();
                    TapToStartText.Show();
                }
                else if(gameState==GameStates.Started)
                {
                    ScoreText.Show();
                    TapToStartText.Hide();
                }
                else if(gameState==GameStates.GameOver)
                {
                    ScoreText.Hide();
                    TapToStartText.Hide();
                }
            }).UnRegisterWhenGameObjectDestroyed(gameObject);
        }

        protected override void OnOpen(IUIData uiData = null)
        {
        }

        protected override void OnShow()
        {
        }

        protected override void OnHide()
        {
        }

        protected override void OnClose()
        {
        }
    }
}
